package com.digitalchina.lxnsy.viewholder;

import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.constant.Constant;
import com.digitalchina.lxnsy.entity.FarmAccountsVO;
import com.digitalchina.lxnsy.toolkit.DateStyle;
import com.digitalchina.lxnsy.toolkit.DateUtil;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/8/31 11:10
 * 修改备注：
 * ================================================
 */

public class FarmAccountListHolder extends BaseViewHolder<FarmAccountsVO> {

    private ImageView ivImg;
    private TextView tvMoney;
    private TextView tvName;
    private TextView tvTime;


    public FarmAccountListHolder(ViewGroup parent) {
        super(parent, R.layout.item_farm_acc_list);
        ivImg = $(R.id.iv_img);
        tvMoney = $(R.id.tv_money);
        tvName = $(R.id.tv_name);
        tvTime = $(R.id.tv_time);
    }

    @Override
    public void setData(FarmAccountsVO data) {
        super.setData(data);

        if (data.getAccountType() != null) {
            for (int i = 0; i < Constant.FARM_ACCOUNT_TYPE_ARRAY.length; i++) {
                if (Constant.FARM_ACCOUNT_TYPE_ARRAY[i].equals(data.getAccountType().getCode())) {
                    ivImg.setImageResource(Constant.FARM_ACCOUNT_IMAGE_ARRAY[i]);
                    break;
                }
            }
        }

        if (data.getType() == 0) {
            //收入
            tvMoney.setText("+" + data.getMoney());
            tvMoney.setTextColor(getContext().getResources().getColor(R.color.app_color));
        } else {
            //支出
            tvMoney.setText("-" + data.getMoney());
            tvMoney.setTextColor(getContext().getResources().getColor(R.color.colorFontRed));
        }


        tvName.setText(data.getAccountType() != null ? data.getAccountType().getName() : "其他");

        tvTime.setText(DateUtil.StringToString(data.getAccountDate(), DateStyle.YYYY_MM_DD));
    }

}
